package com.muqi.server.controller;

import com.muqi.server.common.response.ResponseClass;
import com.muqi.server.domain.bo.CollaborativeFilteringBO;
import com.muqi.server.service.CollaborativeFilteringService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "*",allowedHeaders = "*", maxAge = 3600)
@RestController
@RequestMapping("/CF")
@RequiredArgsConstructor
public class CollaborativeFilteringController {
    @Autowired
    private CollaborativeFilteringService service;

    @GetMapping("/getCFList")
    public ResponseEntity<?> getGenderCount(@RequestParam(required = false) String name) {
        if (name == null) {
            List<CollaborativeFilteringBO> list = service.getCollaborativeFiltering();
            return ResponseEntity.ok().body(new ResponseClass(200, list, "获取成功"));
        }
        try {
            List<CollaborativeFilteringBO> list = service.getCollaborativeFiltering(name);
            return ResponseEntity.ok().body(new ResponseClass(200, list, "获取成功"));
        }catch (Exception e)
        {
            return ResponseEntity.ok().body(new ResponseClass(400, null, e.getMessage()));
        }
    }
}
